package com.stormrage.edu.dao.edu.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.stormrage.edu.dao.edu.EduLecDao;
import com.stormrage.entity.edu.EduLec;
import com.stormragetech.core.dao.MysBaseDao;
import com.stormragetech.core.exception.StormrageTechException;

/**
 * @Title: EduLecDaoImpl.java
 * @Package com.stormrage.edu.dao.edu.impl
 * @Description: 讲师 Dao
 * @author www.stormragetech.com
 * @date 2016年4月10日
 * @version V1.0
 */
@Repository
public class EduLecDaoImpl extends MysBaseDao implements EduLecDao {

	private static final Logger logger = LoggerFactory.getLogger(EduLecDaoImpl.class);

	@Override
	public Integer create(final EduLec arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Create 】- 开始运行 ");

		final String query = "INSERT INTO edu_lec (lec, detail, image, idx) VALUES" + " (:lec, :detail, :image, :idx)";
		logger.debug(" 数据库执行语句为 " + query);

		Integer index = create(query, arg0);

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Create 】- 完成运行 ");
		return index;
	}

	@Override
	public void update(final EduLec arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Update 】- 开始运行 ");

		final String query = "UPDATE edu_lec SET lec = :lec, detail = :detail, image = :image, idx = :idx WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Update 】- 完成运行 ");
	}

	@Override
	public void updateIdx(final EduLec arg0) throws StormrageTechException {

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Update 】- 开始运行 ");

		final String query = "UPDATE edu_lec SET idx = :idx WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, arg0);

		logger.debug(" 【 Dao 】-【 EduLecDao 】-【 Update 】- 完成运行 ");
	}

	@Override
	public void delete(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 Delete 】- 开始运行 ");

		final String query = "DELETE FROM edu_lec WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		update(query, map);

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 Delete 】- 完成运行 ");
	}

	@Override
	public Integer queryCount(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryCount 】- 开始运行 ");

		final String query = "SELECT COUNT(*) FROM edu_lec " + map.get("query");
		logger.debug(" 数据库执行语句为 " + query);

		Integer count = queryCount(query, map);

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryCount 】- 完成运行 ");
		return count;
	}

	@Override
	public EduLec queryById(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryById 】- 开始运行 ");

		final String query = "SELECT * FROM edu_lec WHERE id = :id";
		logger.debug(" 数据库执行语句为 " + query);

		EduLec entity = queryObject(query, EduLec.class, map);

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryById 】- 完成运行 ");
		return entity;
	}

	@Override
	public List<EduLec> queryList() throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM edu_lec ORDER BY id DESC";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduLec> array = queryList(query, EduLec.class);

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryList 】- 完成运行 ");
		return array;
	}

	@Override
	public List<EduLec> queryList(final Map<String, Object> map) throws StormrageTechException {

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryList 】- 开始运行 ");

		final String query = "SELECT * FROM edu_lec " + map.get("query") + " LIMIT :startPage, :size";
		logger.debug(" 数据库执行语句为 " + query);

		List<EduLec> array = queryList(query, EduLec.class, map);

		logger.debug(" 【 Dao 】- 【 EduLecDao 】- 【 QueryList 】- 完成运行 ");
		return array;
	}

}
